/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.repository;


import me.zhengjie.pojo.sqlServer.PPInventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
* @website https://eladmin.vip
* @author xinglin
* @date 2024-08-03
**/
public interface PPInventoryRepository extends JpaRepository<PPInventory, Integer>, JpaSpecificationExecutor<PPInventory> {


//    @Query("select p from PPInventory p where p.ppBatch= ?1")
//    PPInventory findByBatchNum(String ppBatch);


    @Query("select p from PPInventory p where p.batch= ?1 and p.ppBatch =?2")
    PPInventory findByBatchAndBatchNum( String batch,String ppBatch);

    PPInventory findPPInventoryByStorageCode(String storageCode);

    PPInventory findPPInventoryByPalletCode(String palletCode);

    @Query("select ps.id from PPStorage ps where ps.palletCode=?1")
    Integer findStorageIdByPalletCode(String palletCode);

    @Modifying
    @Transactional
    void deletePPInventoryByPalletCode(String palletCode);


    @Query("select i from PPInventory i where i.ppBatch = ?1")
    PPInventory findByPpBatch(String ppBatch);


    @Query("select i from PPInventory i where i.palletCode in ?1")
    List<PPInventory> findPPInventoriesInPalletCodes(List<String> palletCode);

    @Modifying
    @Transactional
    @Query("update PPInventory i set i.outBoundTime = ?1 where i.palletCode = ?2")
    void  updateOutBoundTimeByPalletCode(LocalDateTime outBoundTime,String palletCode);

    PPInventory findPPInventoryById(Integer id);
}